#define COUT(a) cout<<"\n"<<gInterpreter->GetCurrentMacroName()<<" :: "<<a<<"\n"<<"\n"

///usage: run over samples to get trees and plots

void run () ///usage:
{

bool _isSUSY=false; 
bool _isData=false;
bool _isbEnriched=false;
bool _isSUSYMIX=false;
bool _BtagPtEta=true; ///usage: true if you want Btag(pT,Eta). use false if you want Btag(pT)

bool _useMVAFiltering=true; ///usage: if you want to make mva filtering
double _mvaCutLess=-1e10; ///usage:  change it to positive val if you want to select event as cut<_mvaCutLess
double _mvaCutMore=-1e10; ///usage: change it to positive val if you want to select event as cut>_mvaCutMore
_mvaCutLess=2e-1;


int _usernevt = 100000; ///usage: if you want to run on smaller number of events than it's store in nTuples
			///usage: use positive val, if you want to use this option otherwise use negative val

 _usernevt =-1;

TString SUSYMASS;

ifstream f("theMergeList.txt");

///Parsing of file:
TString  str;

///Read first line
str.ReadLine(f);

if (str.Length()>0 )
{
TObjArray* tokens=str.Tokenize(TString('/'));


for (int dd=0;dd<tokens->GetEntries();dd++)    {
if ( TString(tokens->At(dd)->GetName()).Contains("SUSY")){
COUT("SUSY sample FOUND");
_isSUSY=true;

if (!_isSUSYMIX) {
TString str2 = tokens->At(dd)->GetName();
TObjArray* tokens2=str2.Tokenize(TString('_'));
TString str3 = tokens2->At(1)->GetName();

str3.ReplaceAll("M-","");
SUSYMASS=str3;

COUT(str3.Data());
}
}

if ( TString(tokens->At(dd)->GetName()).Contains("bEnriched")){
COUT("bEnriched sample FOUND");
_isbEnriched=true;
}

if ( TString(tokens->At(dd)->GetName()).Contains("MultiJet")){
COUT("data sample FOUND");
_isData=true;
}

}
}

//gROOT->ProcessLine(".L Sphericity.h+");
gROOT->ProcessLine(".L EventShapeVariables.cc+");
gROOT->ProcessLine(".L  TtSemiLepSignalSel.cc+");
gROOT->ProcessLine(".L MVATrainer.h+");
if (_useMVAFiltering) {
gROOT->ProcessLine(".L MVAComputer2.h+");
TString str6;
if (_mvaCutLess>0 && _mvaCutMore<0) {

 gSystem->AddIncludePath("-DMVA");
 str6=TString("-DMVACUTLESS=")+Form("%.3f",_mvaCutLess);
gSystem->AddIncludePath(str6.Data());

} //if 

if (_mvaCutLess<0 && _mvaCutMore>0) {

 gSystem->AddIncludePath("-DMVA");
 str6=TString("-DMVACUTMORE=")+Form("%.3f",_mvaCutMore);
gSystem->AddIncludePath(str6.Data());

} //if 

} ///if _useMVAFiltering

if (_usernevt>0) {
TString str7=TString("-DUSERNEVT=")+Form("%d",_usernevt);
gSystem->AddIncludePath(str7.Data());

} ///if _usernevt

if (!_BtagPtEta) gSystem->AddIncludePath("-DMISTAGPROBFUN");
 
if (_isSUSY) {	
gSystem->AddIncludePath("-DSUSY"); 
gSystem->AddIncludePath("-DMC");
if (SUSYMASS.Length()>0) 
{
TString str5=TString("-DSUSYMASS=")+SUSYMASS;
gSystem->AddIncludePath(str5.Data());

}
//gROOT->ProcessLine(".L readtribn.C+");
} 
else if ( _isData ){
gSystem->AddIncludePath("-DDATA");
//gROOT->ProcessLine(".L readtribn.C+");

}

else if (_isbEnriched)
{
gSystem->AddIncludePath("-DBENRICHED");
gSystem->AddIncludePath("-DMC");
//gROOT->ProcessLine(".L readtribn.C+");
}
//else

gROOT->ProcessLine(".L readtribn.C+");
gROOT->ProcessLine("readtribn()");

gSystem->Exec("rm *.so");
gSystem->Exec("rm *.d");

}
